# Maintainer: Justin Kromlinger <hashworks@archlinux.org>
pkgname=srrdb-terminal-client
pkgver=1.2.1
pkgrel=1
pkgdesc="A terminal client to access srrdb.com"
arch=("loong64" "x86_64")
url="https://github.com/hashworks/srrdb-Terminal-Client"
license=("GPL3")
depends=('glibc') # because of linkmode external
makedepends=('go' 'git')
source=("git+${url}.git#tag=v${pkgver}?signed")
validpgpkeys=('5C81C9D6C8D7475DF65A0C884FE7F4FEAC8EBE67')
sha256sums=('SKIP')

prepare(){
	cd "srrdb-Terminal-Client"
	mkdir -p build/
}

build() {
	cd "srrdb-Terminal-Client"
	export CGO_ENABLED=0
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
	go build \
		-trimpath \
		-buildmode=pie \
		-mod=readonly \
		-modcacherw \
		-ldflags "-linkmode external -extldflags \"${LDFLAGS}\" -X main.VERSION=\"${pkgver}\" -X main.BUILD_DATE=\"$(date -d@"${SOURCE_DATE_EPOCH}" +"%Y-%m-%d_%H:%M:%S")\"" \
		-o build .
}

check() {
	cd "srrdb-Terminal-Client"
	go test .
}

package() {
	cd "srrdb-Terminal-Client"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -Dm755 "build/srrdb-Terminal-Client" "${pkgdir}/usr/bin/srrdb"
}
